package xyz.xxpc.springcloud.test;

import java.sql.*;

public class DbTool {
    static {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    public static int userCount() throws SQLException, InterruptedException {
        Connection connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/users?useUnicode=true&characterEncoding=UTF-8&serverZone=Asia/Shanghai",
                "root",
                "123456"
        );
//        Thread.sleep(500);
        Statement statement = connection.createStatement();
        ResultSet rs = statement.executeQuery("select count(1) from users");

        int count = 0;
        if(rs.next()){
            count = rs.getInt(1);
        }
        rs.close();
        statement.close();
        connection.close();
        return count;
    }
}
